<?php
/**
 * Created by xuan.
 * Author: xuan
 * Date: 2018/8/3
 * Time: 18:24
 */

namespace app\api\model;
use think\Db;
use think\Request;

class Member extends BaseModel
{	
	protected $table = 'member';
	
	public static function selectOneMemberByWx($weixin){
		$data = model("Member")->where(array("weixin"=>$weixin))->find();
		return $data;
	}
	
	public static function selectOneMemberByTel($tel){
		$data = model("Member")->where("tel",$tel)->find();
		return $data;
	}
	
	public static function selectOneMemberByIdnum($idnum){
		$data = model("Member")->where(array("idnum"=>$idnum))->find();
		return $data;
	}
	
	public static function selectOneMemberByID($id){
		$data = model("Member")->where(array("id"=>$id))->find();
		return $data;
	}
	
	public static function addOneMember($all)
    {
		$data = Member::create([
			'name' => $all['name'],
			'password' => $all['password'],
			'weixin' => $all['weixin'],
			'tel' => $all['tel'],
			'email' => $all['email'],
// 			'idnum' => $all['idnum'],
// 			'idpic1' => $all['idpic1'],
            'face'=> $all['face'],
			'idpic2' => $all['idpic2'],
			'addrvalue' => $all['addrvalue'],
			'addr' => $all['addr'],
			'fid' => $all['fid'],
			'pid_path' => $all['pid_path'],
			'authortime' => date('Y-m-d H:i:s',strtotime("+1 year")),
			'addtime' => date('Y-m-d H:i:s',time()),
			'updatetime' => date('Y-m-d H:i:s',time()),
		    'passport_uid'=>$all['passport_uid'],
		    'openid'=>$all['openid'],
		    'bind_time'=>$all['bind_time'],
		    'ip'=>Request::instance()->ip(1),
		]);
		
		  
		return $data;
    }
	
	public static function MemberLists(){
		$data = model("Member")->select();
		return $data;
	}
	
	/**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     * 查询详情
     */
    public static function getListByWhere($where, $page = 0, $pageSize = 10 ,$order = "id DESC"){
        $pageSize = $pageSize <= 0 ? 10 : $pageSize;
        $list = Db::name('Member')->where($where)->limit($page, $pageSize)->order($order)->select();
		return $list;
    }
    
    public static function getByIds($ids,$fields = '*'){
        return Db::name('Member')->whereIn('id',$ids)->column($fields,'id');
    }
	
	public static function getCount($where = ''){
        return Db::name('Member')->where($where)->count();
    } 
	
    public static function shenhe($all){
		$count = Db::name('Member')->where('id',$all['id'])->update(['status' => $all['status'],'beizhu' => $all['beizhu']]);
		return $count;
	}
	
	public static function xgmm($all){
		$count = Db::name('Member')->where('id',$all['mid'])->update(['password' => $all['password'],'updatetime' => date('Y-m-d H:i:s',time())]);
		return $count;
	}
	
	
	public function getItemsByIds($ids,$fields='*'){
	    if(empty($ids)){
	        return [];
	    }
	    return Db::name($this->table)->whereIn('id',$ids)->column($fields,'id');
	}
	
}